<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Baoming extends Model
{
    protected $table = 'baoming';

    public static $switch = [
        'on' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
        'off' => ['value' => 1, 'text' => '是', 'color' => 'success'],
    ];


    public static $readed = [
        'on' => ['value' => 0, 'text' => '未读', 'color' => 'danger'],
        'off' => ['value' => 1, 'text' => '已读', 'color' => 'success'],
    ];

    public function setContentAttribute($content)
    {
        if (is_array($content)) {
            $this->attributes['content'] = serialize($content);
        }
    }

    public function getContentAttribute($content)
    {
        $str = '';

        if (!is_null($content)) {
            $arr = unserialize($content);

            if (!empty($content)) {
                foreach ($arr as $k => $v) {
                    $str .= $k . ':' . $v . '<br/>';
                }
            }
        }
        return $str;
    }

}
